@extends('_layouts.default')
@section('content')
    <!-- this page specific styles -->
    <link rel="stylesheet" href="{{ URL::asset('/') }}/css/compiled/form-showcase.css" type="text/css" media="screen" />
    <script type="text/javascript" src="{{ URL::asset('/') }}/js/jquery.ajaxfileupload.js"></script>
    <div id="pad-wrapper" class="form-page">
    <div class="row-fluid form-wrapper">
    <!-- left column -->
    <div class="span11 column">
        <form method="post" action={{ URL('admin/infoSave') }} />
        <input name="_token" type="hidden" value="{{ csrf_token() }}" />
        <input name="infoData[id]" type="hidden" value="{{$info->id or ''}}" />
        <input name="infoData[index_main_img]" type="hidden" id="hidden_index_main_img_id" value="{{$info->index_main_img or ''}}" />
        <input name="infoData[main_img]" type="hidden" id="hidden_main_img_id" value="{{$info->main_img or ''}}" />
        <div class="field-box">
            <label>标题：</label>
            <input class="span10" name="infoData[title]" type="text" value="{{$info->title or ''}}" />
        </div>
        <div class="field-box">
            <label>类别：</label>
            <div class="ui-select">
                <select name="infoData[firstColumnId]" id="first_web_columns">
                    <option value="0">请选择</option>
                    @foreach ($firstWebColumns as $firstWebColumn)
                    <option value="{{$firstWebColumn->id }}" @if(isset($info->first_column_id) && $info->first_column_id == $firstWebColumn->id) selected="selected" @endif>{{$firstWebColumn->column_name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="ui-select">
                <select name="infoData[secondColumnId]" id="second_web_columns">
                    <option value="0">请选择</option>
                    @foreach ($secondWebColumns as $secondWebColumn)
                    <option value="{{$secondWebColumn->id }}" @if(isset($info->column_id) && $info->column_id == $secondWebColumn->id) selected="selected" @endif>{{$secondWebColumn->column_name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="field-box" id = "ext_type_select" style="display: none;">
            <label>详细类别：</label>
            @foreach ($extFields as $extField)
            @if($extRelate = isset($extRelates->field_id)?$extRelates->field_id:0)
            @endif
            <div class="ui-select">
                <select name="infoData[ext][{{$extField->field_name}}]">
                    @foreach ($extField->field_option as $fieldKey=>$fieldValue)
                    <option value="{{$fieldKey }}" @if($extRelate == $fieldKey) selected="selected" @endif>{{$fieldValue}}</option>
                    @endforeach
                </select>
            </div>
            @endforeach
        </div>
        <div class="field-box">
            <label>首页主图：</label>
            <div class="span3 avatar-box">
                <div class="personal-image">
                    <div  id="index_main_img_box">
                        @if(isset($info->index_main_img) && '' != $info->index_main_img)
                            <img src="{{$info->index_main_img}}" class="avatar img-circle">
                        @endif
                    </div>
                    <input type="file" name="image" id="upload_index_main_img">
                </div>
            </div>
        </div>
        <div class="field-box">
            <label>详情页主图：</label>
            <div class="span3 avatar-box">
                <div class="personal-image">
                    <div  id="main_img_box">
                        @if(isset($info->main_img) && '' != $info->main_img)
                            <img src="{{$info->main_img}}" class="avatar img-circle">
                        @endif
                    </div>
                    <input type="file" name="image" id="upload_main_img">
                </div>
            </div>
        </div>
        <div class="field-box">
            <label>简介：</label>
            <textarea class="span10" name="infoData[intro]" rows="4">{{$info->intro or ''}}</textarea>
        </div>
        <div class="field-box">
            <label>搜索优化keywords：</label>
            <input class="span10" name="infoData[keywords]" type="text" value="{{$info->keywords or ''}}" />
        </div>
        <div class="field-box">
            <label>搜索优化description：</label>
            <input class="span10" name="infoData[description]" type="text" value="{{$info->description or ''}}" />
        </div>
        <div class="field-box">
            <label>分页：</label>
            <span class="value">资讯分为</span>
            <input class="span1 inline-input" name="infoData[pagecount]" type="text" value="{{$info->pagecount or 1}}"><span class="value">页</span>
        </div>
        <div class="field-box">
            <label>排序：</label>
            <div class="ui-select">
                <select name="infoData[order_id]">
                    <option value="10000">正常</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                    <option value="11">11</option>
                    <option value="12">12</option>
                    <option value="13">13</option>
                    <option value="14">14</option>
                    <option value="15">15</option>
                    <option value="16">16</option>
                    <option value="17">17</option>
                    <option value="18">18</option>
                    <option value="19">19</option>
                    <option value="20">20</option>
                    <option value="21">21</option>
                    <option value="22">22</option>
                    <option value="23">23</option>
                    <option value="24">24</option>
                    <option value="25">25</option>
                    <option value="26">26</option>
                    <option value="27">27</option>
                    <option value="28">28</option>
                    <option value="29">29</option>
                    <option value="30">30</option>
                </select>
            </div>
        </div>
        <div class="field-box">
            <label>保存：</label>
            <input type="submit" class="btn-glow primary" value="保存" onclick="getContents();return false;">
        </div>
        </form>
    </div>
    <script>
        $("#first_web_columns").change(function(){
            var parentId = this.value;
            if(19 == parentId){
                $("#ext_type_select").show();
            }else{
                $("#ext_type_select").hide()
            }
            $.ajax({
                url:'/admin/column/get/'+parentId,// 跳转到 action
                type:'get',
                dataType:'json',
                success:function(result) {
                    var strSelectOptionHtml = '<option value="-1">请选择</option>';
                    if(result['code'] == 0 ){
                        for(var i in result['data']){
                            strSelectOptionHtml += '<option value="'+result['data'][i]['id']+'">'+result['data'][i]['column_name']+'</option>'
                        }
                    }
                    $("#second_web_columns").html(strSelectOptionHtml);
                }
            });
        });
        $(document).ready(function() {
            function applyAjaxFileUpload(element,imgName) {
                $(element).AjaxFileUpload({
                    action: "/admin/imageUpload",
                    onSubmit: function(filename) {
                        return true;
                    },
                    onComplete: function(filename, response) {
                        if (typeof(response.msg) === "string") {
                            if(response.code === 0){
                                html = '<img src="'+response.data+'" class="avatar img-circle">';
                                $("#"+imgName+"_box").html(html);
                                $("#hidden_"+imgName+"_id").val(response.data);
                            }else{
                                alert(response.data);
                            }
                            return;
                        }
                    }
                });
            }

            applyAjaxFileUpload("#upload_main_img",'main_img');
            applyAjaxFileUpload("#upload_index_main_img",'index_main_img');
        });
    </script>
@endsection